<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of VMT_GridData2MeanXS</title>
  <meta name="keywords" content="VMT_GridData2MeanXS">
  <meta name="description" content="This routine generates a uniformly spaced grid for the mean cross section and">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- menu.html trunk -->
<h1>VMT_GridData2MeanXS
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>This routine generates a uniformly spaced grid for the mean cross section and</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [A,V] = VMT_GridData2MeanXS(z,A,V,unitQcorrection) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> This routine generates a uniformly spaced grid for the mean cross section and 
 maps (interpolates) individual transects to this grid.   

 (adapted from code by J. Czuba)

 P.R. Jackson, USGS, 12-9-08
 Last modified: F.L. Engel, USGS 2/20/2013</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="VMT_unitQcont.html" class="code" title="function A = VMT_unitQcont(A,V,z)">VMT_unitQcont</a>	VMT_UNITQCONT applies unit discharge continuity correction MCS velocities</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="VMT_ProcessTransects.html" class="code" title="function [A,V,log_text] = VMT_ProcessTransects(z,A,setends,unitQcorrection)">VMT_ProcessTransects</a>	Driver program to process multiple transects at a single cross-section</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="#_sub1" class="code">function mypostcallback_zoom(obj,evd)</a></li><li><a href="#_sub2" class="code">function mypostcallback_pan(obj,evd)</a></li></ul>

<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [A,V] = VMT_GridData2MeanXS(z,A,V,unitQcorrection)</a>
0002 <span class="comment">% This routine generates a uniformly spaced grid for the mean cross section and</span>
0003 <span class="comment">% maps (interpolates) individual transects to this grid.</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% (adapted from code by J. Czuba)</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% P.R. Jackson, USGS, 12-9-08</span>
0008 <span class="comment">% Last modified: F.L. Engel, USGS 2/20/2013</span>
0009 
0010 <span class="comment">%% User Input</span>
0011 
0012 xgdspc      = A(1).hgns; <span class="comment">%Horizontal Grid node spacing in meters</span>
0013 ygdspc      = A(1).vgns; <span class="comment">%double(A(1).Sup.binSize_cm)/100; %Vertical Grid node spacing in meters</span>
0014 
0015 <span class="comment">% For now, take the minumum bin size as the vertical resolution.</span>
0016 <span class="comment">% Later, I will specify this in the GUI (FLE)</span>
0017 <span class="comment">%ygdspc      = min(min(double(A(1).Sup.binSize_cm)/100)); %Vertical Grid node spacing in meters</span>
0018 <span class="keyword">if</span> 0
0019     xgdspc  = V.meddens + V.stddens;  <span class="comment">%Auto method should include 67% of the values</span>
0020     <span class="comment">%disp(['X Grid Node Auto Spacing = ' num2str(xgdspc) ' m'])</span>
0021     log_text = [<span class="string">'X Grid Node Auto Spacing = '</span> num2str(xgdspc) <span class="string">' m'</span>];
0022 <span class="keyword">end</span>
0023 
0024 
0025 <span class="comment">%% Determine uniform mean c-s grid for vector interpolating</span>
0026 
0027 <span class="comment">% Determine mean cross-section velocity vector grid NEW: Allowed for</span>
0028 <span class="comment">% explicit specification of vertical grid node spacing Also, using linspace</span>
0029 <span class="comment">% doesn't necessarily give exactly hgns spaced grid nodes, so the method</span>
0030 <span class="comment">% has been adjusted (this is important for user that want to output to a</span>
0031 <span class="comment">% model grid). A fragment of length&lt;xgdsoc may be truncated. The impact on</span>
0032 <span class="comment">% this for data analysis should be minor, but should be investigated [FLE</span>
0033 <span class="comment">% 3/25/2014]</span>
0034 <span class="comment">% V.mcsDist               = linspace(0,V.dl,floor(V.dl/xgdspc));</span>
0035 V.mcsDist               = 0:xgdspc:V.dl;
0036 V.mcsDepth              = <span class="keyword">...</span>
0037     min(A(1).Wat.binDepth(:)):ygdspc:max(A(1).Wat.binDepth(:));
0038 <span class="comment">% V.mcsDepth              = A(1).Wat.binDepth(:,1);</span>
0039 [V.mcsDist, V.mcsDepth] = meshgrid(V.mcsDist,V.mcsDepth');
0040 
0041 
0042 <span class="comment">% Define the MCS XY points. (REVISED PRJ, 10-18-12)</span>
0043 <span class="comment">% Coordinate assignments depend on the starting</span>
0044 <span class="comment">% point and the slope of the cross section. Theta is limited to 0 to 180</span>
0045 <span class="comment">% (geographic) and 90 to 270 (arithmetic).  For COS, arithmetic angles</span>
0046 <span class="comment">% between 90 and 270 are always negative so no need to add additional IF</span>
0047 <span class="comment">% statement based on the slope.  However, SIN theta (aritmetic) is positive</span>
0048 <span class="comment">% in MFD quadrants 2 and 4 and negative in 1 and 3. Therefore, we use the slope</span>
0049 <span class="comment">% (positive in MFD quadrants 1 and 3, negative in 2 and 4) to determine whether to add or</span>
0050 <span class="comment">% subtract the incremental distances from the start point.  (MFD = mean</span>
0051 <span class="comment">% flow direction, used to define quadrants above and below)</span>
0052 
0053 <span class="keyword">if</span> V.xLeftBank == V.xe <span class="comment">% MFD Quadrants 2 and 3 (east start)</span>
0054     V.mcsX = V.xLeftBank - V.mcsDist(1,:).*cosd(geo2arideg(V.theta));
0055 <span class="keyword">else</span> <span class="comment">% MFD Quadrants 1 and 4 (west start)</span>
0056     V.mcsX = V.xLeftBank + V.mcsDist(1,:).*cosd(geo2arideg(V.theta));
0057 <span class="keyword">end</span>
0058 
0059 <span class="keyword">if</span> V.yLeftBank == V.yn <span class="comment">% MFD Quadrants 1 and 2 (north start)</span>
0060     <span class="keyword">if</span> V.m &gt;= 0 <span class="comment">%MFD Quadrant 2</span>
0061         V.mcsY = V.yLeftBank - V.mcsDist(1,:).*sind(geo2arideg(V.theta)); 
0062     <span class="keyword">else</span> <span class="comment">%MFD Quadrant 1</span>
0063         V.mcsY = V.yLeftBank + V.mcsDist(1,:).*sind(geo2arideg(V.theta));
0064     <span class="keyword">end</span>
0065 <span class="keyword">else</span> <span class="comment">% MFD Quadrants 3 and 4 (south start)</span>
0066     <span class="keyword">if</span> V.m &gt;= 0 <span class="comment">%MFD Quadrant 4</span>
0067         V.mcsY = V.yLeftBank + V.mcsDist(1,:).*sind(geo2arideg(V.theta)); 
0068     <span class="keyword">else</span> <span class="comment">%MFD Quadrant 3</span>
0069         V.mcsY = V.yLeftBank - V.mcsDist(1,:).*sind(geo2arideg(V.theta));
0070     <span class="keyword">end</span>
0071 <span class="keyword">end</span>
0072 
0073 V.mcsX = meshgrid(V.mcsX,V.mcsDepth(:,1));
0074 V.mcsY = meshgrid(V.mcsY,V.mcsDepth(:,1));
0075 
0076 
0077 <span class="comment">% %Plot the MCS on figure 1</span>
0078 <span class="comment">% figure(1); hold on</span>
0079 <span class="comment">% plot(V.xLeftBank,V.yLeftBank,'gs','MarkerFaceColor','g'); hold on  %Green left bank start point</span>
0080 <span class="comment">% plot(V.xRightBank,V.yRightBank,'rs','MarkerFaceColor','r'); hold on %Red right bank end point</span>
0081 <span class="comment">% plot(V.mcsX(1,:),V.mcsY(1,:),'k+'); hold on</span>
0082 <span class="comment">% figure(1); set(gca,'DataAspectRatio',[1 1 1],'PlotBoxAspectRatio',[1 1 1])</span>
0083 <span class="comment">% clear zi</span>
0084 <span class="comment">%</span>
0085 <span class="comment">% % Format the ticks for UTM and allow zooming and panning</span>
0086 <span class="comment">% figure(1);</span>
0087 <span class="comment">% ticks_format('%6.0f','%8.0f'); %formats the ticks for UTM</span>
0088 <span class="comment">% hdlzm_fig1 = zoom;</span>
0089 <span class="comment">% set(hdlzm_fig1,'ActionPostCallback',@mypostcallback_zoom);</span>
0090 <span class="comment">% set(hdlzm_fig1,'Enable','on');</span>
0091 <span class="comment">% hdlpn_fig1 = pan;</span>
0092 <span class="comment">% set(hdlpn_fig1,'ActionPostCallback',@mypostcallback_pan);</span>
0093 <span class="comment">% set(hdlpn_fig1,'Enable','on');</span>
0094 
0095 
0096 <span class="comment">%% If specified, correct the streamwise velocity by enforcing mass</span>
0097 <span class="comment">% flux (capacitor) continuity</span>
0098 <span class="keyword">if</span> unitQcorrection
0099     A = <a href="VMT_unitQcont.html" class="code" title="function A = VMT_unitQcont(A,V,z)">VMT_unitQcont</a>(A,V,z);
0100 <span class="keyword">end</span>
0101 
0102 <span class="comment">%% Interpolate individual transects onto uniform mean c-s grid</span>
0103 <span class="comment">% Fill in uniform grid based on individual transects mapped onto the mean</span>
0104 <span class="comment">% cross-section by interpolating between adjacent points</span>
0105 <span class="comment">%</span>
0106 <span class="comment">% Originally, the data matrices contained monotonic, finite values. With</span>
0107 <span class="comment">% the inclusion of RiverRay data, this assuption is no longer valid. To</span>
0108 <span class="comment">% interpolate the quasi-scattered data requires vectorizing and isolating</span>
0109 <span class="comment">% the valid data, and then using the TriScatteredInterp class. Ultimately,</span>
0110 <span class="comment">% this method should produce the same results with RioGrande data, but with</span>
0111 <span class="comment">% marked speed improvements (vecotrized operations are faster in Matlab).</span>
0112 <span class="comment">% NOTE: TriScattertedInterp has been replaced by scatteredInterpolant in</span>
0113 <span class="comment">% R2013+</span>
0114 <span class="comment">% [FLE 3/25/2014]</span>
0115 
0116 XI = V.mcsDist(:);
0117 YI = V.mcsDepth(:);
0118 
0119 <span class="comment">%ZI = interp2(X,Y,Z,XI,YI)</span>
0120 <span class="keyword">for</span> zi = 1 : z
0121     <span class="comment">% Vectorize inputs to interp2, index valid data, and preallocate the</span>
0122     <span class="comment">% result vectors</span>
0123     [nrows,ncols] = size(A(zi).Comp.itDist);
0124     X             = A(zi).Comp.itDist; 
0125     Y             = A(zi).Comp.itDepth;
0126     valid         = ~isnan(X) &amp; ~isnan(Y);
0127            
0128     <span class="comment">% Inputs</span>
0129     bs  = A(zi).Clean.bs(:,A(zi).Comp.vecmap);
0130     vE  = A(zi).Clean.vEast(:,A(zi).Comp.vecmap);
0131     vN  = A(zi).Clean.vNorth(:,A(zi).Comp.vecmap);
0132     vV  = A(zi).Clean.vVert(:,A(zi).Comp.vecmap);
0133     vEr = A(zi).Clean.vError(:,A(zi).Comp.vecmap);
0134     
0135     <span class="comment">% Create scatteredInterpolant class</span>
0136     F = TriScatteredInterp(X(valid),Y(valid),bs(valid));
0137     
0138     <span class="comment">% Interpolate to each output</span>
0139     mcsBack  = F(XI,YI);
0140     F.V      = vE(valid);
0141     mcsEast  = F(XI,YI);
0142     F.V      = vN(valid);
0143     mcsNorth = F(XI,YI);
0144     F.V      = vV(valid);
0145     mcsVert  = F(XI,YI);
0146     F.V      = vEr(valid);
0147     mcsError = F(XI,YI);
0148     
0149     <span class="comment">% Reshape and save to outputs</span>
0150     A(zi).Comp.mcsBack  = reshape(mcsBack  ,size(V.mcsX));
0151     A(zi).Comp.mcsEast  = reshape(mcsEast  ,size(V.mcsX));
0152     A(zi).Comp.mcsNorth = reshape(mcsNorth ,size(V.mcsX));
0153     A(zi).Comp.mcsVert  = reshape(mcsVert  ,size(V.mcsX));
0154     A(zi).Comp.mcsError = reshape(mcsError ,size(V.mcsX));
0155     
0156     <span class="comment">%A(zi).Comp.mcsBack = interp2(A(zi).Comp.itDist, A(zi).Comp.itDepth, ...</span>
0157     <span class="comment">%    A(zi).Clean.bs(:,A(zi).Comp.vecmap),V.mcsDist, V.mcsDepth);</span>
0158     <span class="comment">%A(zi).Comp.mcsBack(A(zi).Comp.mcsBack&gt;=255) = NaN;</span>
0159     <span class="comment">%A(zi).Comp.mcsEast = interp2(A(zi).Comp.itDist, A(zi).Comp.itDepth, ...</span>
0160     <span class="comment">%    A(zi).Clean.vEast(:,A(zi).Comp.vecmap), V.mcsDist, V.mcsDepth);</span>
0161     <span class="comment">%A(zi).Comp.mcsNorth = interp2(A(zi).Comp.itDist, A(zi).Comp.itDepth, ...</span>
0162     <span class="comment">%    A(zi).Clean.vNorth(:,A(zi).Comp.vecmap), V.mcsDist, V.mcsDepth);</span>
0163     <span class="comment">%A(zi).Comp.mcsVert = interp2(A(zi).Comp.itDist, A(zi).Comp.itDepth, ...</span>
0164     <span class="comment">%    A(zi).Clean.vVert(:,A(zi).Comp.vecmap), V.mcsDist, V.mcsDepth);</span>
0165     
0166     <span class="comment">%Compute magnitude</span>
0167     A(zi).Comp.mcsMag = sqrt(A(zi).Comp.mcsEast.^2 + A(zi).Comp.mcsNorth.^2);
0168     
0169     
0170     <span class="comment">%For direction, compute from the velocity components</span>
0171     A(zi).Comp.mcsDir = ari2geodeg((atan2(A(zi).Comp.mcsNorth,A(zi).Comp.mcsEast))*180/pi); 
0172     
0173     A(zi).Comp.mcsBed  = interp1(A(zi).Comp.itDist(1,:),<span class="keyword">...</span>
0174         nanmean(A(zi).Nav.depth(A(zi).Comp.vecmap,:),2),V.mcsDist(1,:));
0175     
0176 <span class="keyword">end</span>
0177 
0178 <span class="comment">% clear zi</span>
0179 
0180 <span class="comment">%%%%%%%%%%%%%%%%</span>
0181 <span class="comment">% SUBFUNCTIONS %</span>
0182 <span class="comment">%%%%%%%%%%%%%%%%</span>
0183 <a name="_sub1" href="#_subfunctions" class="code">function mypostcallback_zoom(obj,evd)</a>
0184 ticks_format(<span class="string">'%6.0f'</span>,<span class="string">'%8.0f'</span>); <span class="comment">%formats the ticks for UTM (when zooming)</span>
0185 
0186 <a name="_sub2" href="#_subfunctions" class="code">function mypostcallback_pan(obj,evd)</a>
0187 ticks_format(<span class="string">'%6.0f'</span>,<span class="string">'%8.0f'</span>); <span class="comment">%formats the ticks for UTM (when panning)</span></pre></div>
<hr><address>Generated on Wed 04-Jun-2014 14:21:02 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>